-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn screen off when closing scrcpy #824
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR.
I think this should be an option: I often plug my device just to type or copy-paste things from the computer, I don't want it to be turned off just because I close scrcpy.
app/src/control_msg.h
Outdated
@@ -25,6 +25,7 @@ enum control_msg_type { | |||
CONTROL_MSG_TYPE_GET_CLIPBOARD, | |||
CONTROL_MSG_TYPE_SET_CLIPBOARD, | |||
CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE, | |||
CONTROL_MSG_TYPE_TURN_SCREEN_OFF, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to distinguish between "turn screen off but keep device on" (like here) and "turn screen off and device off (standby)". (There is already some naming confusion in the current codebase, if you have any suggestion…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "lock screen" vs "turn screen off"?
I merged the first commit fixing the log 👍 |
I have pushed v2:
However, I found that server may be killed before screen off. |
In my TODO list, I plan to implement something similar to #679 to be able to cleanup properly:
This will be a requirement to merge this PR. |
Now that there is a real cleanup, you could implement it 😉 (I suggest |
Ok, I will look it. |
Hi, @rom1v There is a problem about power off screen in Maybe Thank you. |
As a quick-and-dirty solution, maybe you could expose a static diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java
index a8fdf677..9fb365ff 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java
@@ -157,16 +157,20 @@ public final class Device {
return supportsInputEvents;
}
+ public static boolean injectEvent(InputEvent inputEvent, int mode, int displayId) {
+ if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
+ return false;
+ }
+
+ return SERVICE_MANAGER.getInputManager().injectInputEvent(inputEvent, mode);
+ }
+
public boolean injectEvent(InputEvent inputEvent, int mode) {
if (!supportsInputEvents()) {
throw new AssertionError("Could not inject input event if !supportsInputEvents()");
}
- if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
- return false;
- }
-
- return SERVICE_MANAGER.getInputManager().injectInputEvent(inputEvent, mode);
+ return injectEvent(inputEvent, mode, displayId);
}
public boolean injectEvent(InputEvent event) { Then, you have to transmit both the displayId and the flag to NOT turn off if control is disabled. What do you think? |
Oh, yes. This solution works. However, I am thinking about future. It will have more and more things that need to be done in For infrastructure, in my opinion, in What do you think? |
After the struct screen is initialized, the window and the renderer are necessarily valid, so there is no need o check in screen_destroy().
This paves the way to handle EVENT_NEW_FRAME from screen.c, by allowing to call screen_update_frame() without an explicit video_buffer instance.
Now that all screen-related events are handled from screen.c, there is no need for a separate method for window events.
It could be great to serialize some structure between the main process and the cleanup process indeed. However, this structure should not be the existing (I don't know if in the end such a structure would be helpful compared to passing each option as argument.) But yes, it would be great to share the common part of the |
Ok, I will pass Thank you for your help. |
Signed-off-by: Yu-Chen Lin <[email protected]>
Hi, @rom1v I have added two commits about this features. First, I export a series static methods for powering off. Second, make Thanks. |
Thank you very much for your work 👍 I just tested, and I found a problem (on a Nexus 5): the "power off" cleanup seems to interact badly with the "restore normal power mode" cleanup, which is executed whenever the screen is on on exit. As a result, I tried with these changes: diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index 7dda83fb..26012409 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -84,16 +84,14 @@ public final class CleanUp {
}
}
- if (restoreNormalPowerMode) {
- Ln.i("Restoring normal power mode");
- if (Device.isScreenOn()) {
+ if (Device.isScreenOn()) {
+ if (powerOffScreen) {
+ Ln.i("Power off screen");
+ Device.powerOffScreen(displayId);
+ } else if (restoreNormalPowerMode) {
+ Ln.i("Restoring normal power mode");
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
}
}
-
- if (powerOffScreen) {
- Ln.i("Power off screen");
- Device.powerOffScreen(displayId);
- }
}
} It improves the behavior. But I have an additional issue that can I cannot explain: if I keep touching the device (I keep one finger on the device screen) while I close the scrcpy window, it blocks and never power off the screen. It is unexpected, because if I keep one finger on the screen and press MOD+p to power off the screen, then it works. 😕 If I add some logs (and even if I always return diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index 26012409..2c54558c 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -84,7 +84,9 @@ public final class CleanUp {
}
}
+ Ln.i("CLEANUP #1");
if (Device.isScreenOn()) {
+ Ln.i("CLEANUP #2");
if (powerOffScreen) {
Ln.i("Power off screen");
Device.powerOffScreen(displayId);
@@ -93,5 +95,6 @@ public final class CleanUp {
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
}
}
+ Ln.i("CLEANUP #3");
}
}
diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java
index 624c9fa0..3ee248d3 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java
@@ -212,7 +212,7 @@ public final class Device {
}
public static boolean isScreenOn() {
- return SERVICE_MANAGER.getPowerManager().isScreenOn();
+ return true; //SERVICE_MANAGER.getPowerManager().isScreenOn();
}
public synchronized void setRotationListener(RotationListener rotationListener) { Then it blocks:
If I replace |
In fact, it seems the cleanup process is killed (the process does not appear in Btw, if I add a It's probably due to the
(I don't have this problem on my OnePlus 7 Pro) |
Hmm, I am not familiar with BTW, I don't notice this problem in my note10+ with android 11. diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index 7dda83fb..26012409 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -84,16 +84,14 @@ public final class CleanUp {
}
}
- if (restoreNormalPowerMode) {
- Ln.i("Restoring normal power mode");
- if (Device.isScreenOn()) {
+ if (Device.isScreenOn()) {
+ if (powerOffScreen) {
+ Ln.i("Power off screen");
+ Device.powerOffScreen(displayId);
+ } else if (restoreNormalPowerMode) {
+ Ln.i("Restoring normal power mode");
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
}
}
-
- if (powerOffScreen) {
- Ln.i("Power off screen");
- Device.powerOffScreen(displayId);
- }
}
} I will apply this change as it is more correct. Thank you for your test and survey. |
Signed-off-by: Yu-Chen Lin <[email protected]>
Thank you 👍 Merged into |
PR #824 <#824> Signed-off-by: Yu-Chen Lin <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
PR #824 <#824> Signed-off-by: Yu-Chen Lin <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
This avoids to pass each option as individual parameter and parse them manually (it's still "manual" in the Parcelable implementation). Refs #824 <#824 (comment)>
This avoids to pass each option as individual parameter and parse them manually (it's still "manual" in the Parcelable implementation). Refs #824 <#824 (comment)> Reviewed-by: Yu-Chen Lin <[email protected]>
This avoids to pass each option as individual parameter and parse them manually (it's still "manual" in the Parcelable implementation). Refs #824 <#824 (comment)> Reviewed-by: Yu-Chen Lin <[email protected]>
Fix #714